//
//  CCNetWorkingTooks.swift
//  swift_weibo
//
//  Created by ccl on 16/2/29.
//  Copyright © 2016年 LittleBoy. All rights reserved.
//

import UIKit
import AFNetworking

class CCNetWorkingTooks: AFHTTPSessionManager {
    
    /* 仿OC版的 单例  有效
    // swift类方法中不能定义静态变量
    static var instance : CCNetWorkingTooks?;
    static var token : dispatch_once_t = 0;
    // 类方法
    class func shareNetWorkingTook() -> CCNetWorkingTooks {
       dispatch_once(&token) { () -> Void in
        instance = CCNetWorkingTooks();
        };
        return instance!;
    }
  */
    
    // swift 版的
    private static let instance : CCNetWorkingTooks = {
        /// baseURL com后面的 / 不能省
        let baseStr = "https://api.weibo.com/";
        let baseUrl = NSURL(string: baseStr)!;
        let tool = CCNetWorkingTooks(baseURL: baseUrl);
        
     let contentType =  NSSet(objects: "application/json", "text/json", "text/javascript", "text/plain") as! Set<String>;
        tool.responseSerializer.acceptableContentTypes = contentType ;
        return tool
    }();
  
    
    class func shareNetWorkingTook() -> CCNetWorkingTooks {
        return instance;
    }
    
    
}
